package com.zhiyou100.controller;

import com.zhiyou100.entity.Emp;
import com.zhiyou100.service.EmpService;
import com.zhiyou100.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 28453
 */
@WebServlet("/empServlet")
public class EmpServlet extends HttpServlet {
    EmpService empService= new EmpServiceImpl();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("EmpServlet1");
        List<Emp> allEmp = empService.getAllEmp();
        System.out.println("EmpServlet2");
        System.out.println(allEmp);
        //存入request域
        request.setAttribute("allEmp",allEmp);
        //跳转
        request.getRequestDispatcher("index.jsp").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       doPost(request,response);
    }
}
